from bs4 import BeautifulSoup
import requests

urlNames = 'https://namecensus.com/top-first-names/top-first-names.html'
urlSurNames = 'https://namecensus.com/data/1000.html'

request_names = requests.get(urlNames)
request_surNames = requests.get(urlSurNames)

soup_names = BeautifulSoup(request_names.text, 'html.parser')
soup_surNames = BeautifulSoup(request_surNames.text, 'html.parser')

name = soup_names.find_all('tr')
surName = soup_surNames.find_all('tr')

for names in name:
    i = 0

    names = names.select('td:nth-of-type(2)')
    if names is not None:
        with open('src/names.txt', 'a') as file:
            file.write(names[i].text.title() + '\n')
            i += 1

for surNames in surName:
    i = 0

    surNames = surNames.select('td:nth-of-type(1)')
    if surNames is not None:
        with open('src/surNames.txt', 'a') as file:
            file.write(surNames[i].text.title() + '\n')
            i += 1
